package test4;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQTopic;

public class TestSubConsumerSyn {
	public static void main(String[] args) throws JMSException {
		ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://10.222.29.178:61616");
		Destination topic = new ActiveMQTopic("topic1");
		Connection con = factory.createConnection();
		con.start();
		
		Session session = con.createSession(true, Session.AUTO_ACKNOWLEDGE);
		MessageConsumer consumer = session.createConsumer(topic);
		
		//block thread
		TextMessage msg1 = (TextMessage) consumer.receive();
		String string1 = msg1.getText();
		System.out.println(string1);
		
//		int m=2/0;
		TextMessage msg2 = (TextMessage) consumer.receive();
		String string2 = msg2.getText();
		System.out.println(string2);
		session.commit();
		
		consumer.close();
		session.close();
		con.close();
	}

}
